/// @tags: SAM
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 1e6 + 5;

struct Edge {
  int v, nxt;
} e[N << 1];

struct Node {
  int ch[26], len, link;
} sam[N];

int n, las, e_cnt, tot;
int heads[N], siz[N];
char s[N];
LL ans;

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

inline void insert(int c) {
  int cur = ++tot, pos = las;
  sam[0].link = -1;
  sam[cur].len = sam[pos].len + 1;
  siz[cur] = 1;
  while (~pos && !sam[pos].ch[c]) {
    sam[pos].ch[c] = cur;
    pos = sam[pos].link;
  }
  if (pos == -1) {
    sam[cur].link = 0;
  } else {
    int q = sam[pos].ch[c];
    if (sam[q].len == sam[pos].len + 1) sam[cur].link = q;
    else {
      int clone = ++tot;
      sam[clone] = sam[q];
      sam[clone].len = sam[pos].len + 1;
      sam[q].link = sam[cur].link = clone;
      while (~pos && sam[pos].ch[c] == q) {
        sam[pos].ch[c] = clone;
        pos = sam[pos].link;
      }
    }
  }
  las = cur;
}

void dfs(int u) {
  for (int i = heads[u], v; i; i = e[i].nxt) {
    dfs(v = e[i].v);
    siz[u] += siz[v];
    ans += LL(sam[v].len - sam[u].len) * siz[v] * (n - siz[v]);
  }
}

inline int main() {
  cin >> s;
  n = strlen(s);
  reverse(s, s + n);
  for (int i = 0; i < n; ++i) insert(s[i] - 'a');
  for (int i = 1; i <= tot; ++i) add(sam[i].link, i);
  dfs(0);
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4248 [AHOI2013] 差异.in", "r", stdin);
  freopen("P4248 [AHOI2013] 差异.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
